const path = require('path');
const webpack = require('webpack');
const configEnv = process.env.CONFIG_ENV;
const CompressionPlugin = require('compression-webpack-plugin');

const plugins = [
  new webpack.ProvidePlugin({
    feConfig: path.resolve('.', './src/feConfig/' + (configEnv || 'development')),
    Util: path.resolve('.', './src/utils/util'),
    Enums: path.resolve('.', './src/constants/enum')
  })
];

process.env.UNI_PLATFORM === 'h5' && plugins.push(
  new CompressionPlugin({
    test: /\.js$|\.html$|\.css$|\.jpg$|\.jpeg$|\.png/, // 需要压缩的文件类型
    threshold: 10240, // 对超过10k的数据压缩
    deleteOriginalAssets: false, // 不删除源文件
    minRatio: 0.8
  })
);

module.exports = {
  devServer: {
    host: '0.0.0.0',
    port: 8080,
    open: true,
    proxy: {
      '/v1': {
        target: 'https://mock.apifox.com/m1/3563194-0-default',
        changeOrigin: true
      },
      '/v2': {
        target: 'https://mock.apifox.com/m1/3563194-0-default',
        changeOrigin: true
      }
    },
    disableHostCheck: true
  },
  configureWebpack: { plugins },
  transpileDependencies: ['luch-request', 'uview-ui']
};
